package leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class Lc128_2 {

    public int longestConsecutive(int[] nums) {

        HashSet<Integer> set = new HashSet();
        for (int i = 0; i < nums.length; i++) {
            set.add(nums[i]);
        }
        int ans = 0;
        for (int num: set) {
            if (!set.contains(num - 1)) {
                int curNum = num;
                int curLength = 1;
                while (set.contains(curNum + 1)) {
                    curNum += 1;
                    curLength += 1;
                }
                ans = Math.max(ans, curLength);
            }
        }
        return ans;
    }



}
